// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import GameEvent from "../../Commons/GameEvent";
import SaveManager from "../../Managers/SaveManager";
import PlatformManager from "../../Platforms/PlatformManager";

export enum RankEvent {
    UPDATARANK_EVENT = "updataRank_event"
}

const { ccclass, property } = cc._decorator;

@ccclass
export default class RankManager implements IModelManager {
    private static _single: RankManager = null;
    public static get single(): RankManager {
        if (RankManager._single == null) {
            RankManager._single = new RankManager();
        }
        return RankManager._single;
    }

    public rankList: any[] = [];

    initConfig(): void {

    }

    async onUploadRank() {
        var accountData = SaveManager.single.accountData;
        var userdata = SaveManager.single.userdata;
        let result = await PlatformManager.single.basePlatform.sdk.uploadRank(accountData.username, 2, userdata.gateEntity.currentGateId, userdata.playerName);
        if (result.code == 200) {
            console.log("排名: ", result.data.rankList);
            this.rankList = result.data.rankList;
            GameEvent.eventNode.emit(RankEvent.UPDATARANK_EVENT);
        }
    }

}
